package cn.stronglink.asset.module.basicdata.assetModel.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import cn.stronglink.asset.model.AssetModel;
import cn.stronglink.asset.module.basicdata.assetModel.mapper.AssetModelMapper;
import cn.stronglink.suite.core.util.WebUtil;

@Service
@Transactional(rollbackFor=Exception.class) 
public class AssetModelService {

	@Autowired
	private AssetModelMapper assetModelMapper;

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Page<AssetModel> queryAssetModel(Page<AssetModel> page,Map<String, Object>  params) {
		page.setRecords(assetModelMapper.queryAssetModel(page,params));
		return page;	
	}
	
	public void removeAssetModel(Long id){
		assetModelMapper.removeAssetModel(id);	
	}	

	public void insertAssetModel(AssetModel assetModel) {
		assetModel.setId(IdWorker.getId());
		assetModel.setCreateBy(WebUtil.getCurrentUser());
		assetModel.setCreateTime(new Date());
		assetModelMapper.insertAssetModel(assetModel);		
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<AssetModel> queryListAll(Map<String, Object> params) {
		return assetModelMapper.queryListAll(params);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<AssetModel> queryListAllS() {
		return assetModelMapper.queryListAllS();
	}

	public void updateAssetModel(AssetModel assetModel) {
		assetModel.setUpdateBy(WebUtil.getCurrentUser());
		assetModel.setUpdateTime(new Date());
		assetModelMapper.updateAssetModel(assetModel);
		
	}
	
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public int getIsUsedModel(Long id) {
		return assetModelMapper.getIsUsedModel(id);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public AssetModel qryById(Long id) {
		return assetModelMapper.qryById(id);
	}
	

}
